     /*
 * ShapeNode.java
 *
 * Created on September 21, 2006, 9:18 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 * To understand this class, see http://platform.netbeans.org/tutorials/nbm-nodesapi3.html
 */

package org.netbeans.shapesimple.palette;

import java.beans.IntrospectionException;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node.Property;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.Exceptions;
import org.openide.util.lookup.Lookups;

/**
 *
 * @author Geertjan Wielenga
 */
public class ShapeNode extends AbstractNode implements PropertyChangeListener {
    
    //private Shape shape;
    
    public final static String[][] SHAPE_PROPS =
    {
        {
            "number" , "getNumber", "setNumber"
        },
        {
            "category", "getCategory", "setCategory"
        },
        {
            "title", "getTitle", "setTitle"
        },
        {
            "image", "getImage", "setImage"
        }
    };
    
    public static final int SHAPE_PROPS_NAME = 0;
    
    public static final int SHAPE_PROPS_GETTER = 1;
    
    public static final int SHAPE_PROPS_SETTER = 2;
    
    /** Creates a new instance of ShapeNode */
    public ShapeNode(Shape2 key) throws IntrospectionException  {
        super(Children.LEAF, Lookups.fixed( new Object[] {key} ) );
        //this.shape = key;
        setIconBaseWithExtension(key.getImage());
        key.addPropertyChangeListener( this);
        this.setDisplayName( key.getTitle());
    }


    @Override
    protected Sheet createSheet()
    {
        Sheet sheet = Sheet.createDefault();
        
        Shape2 shape = getLookup().lookup( Shape2.class);
        
        Sheet.Set propSet = Sheet.createPropertiesSet();
        propSet.setName("Shape Set");
        propSet.setDisplayName( "Shapes");
        
        try
        {
            Property numberProp = new PropertySupport.Reflection( shape, Integer.class, "getNumber", "setNumber");
            Property categoryProp = new PropertySupport.Reflection( shape, String.class, "getCategory", "setCategory");
            Property titleProp = new PropertySupport.Reflection( shape, String.class, "getTitle", "setTitle");
            Property imageProp = new PropertySupport.Reflection( shape, String.class, "getImage", "setImage");
            
            titleProp.setName( "Title");
            numberProp.setName( "Number");
            categoryProp.setName( "Category");
            imageProp.setName( "Image filename");
            
            propSet.put( imageProp );
            propSet.put( titleProp );
            propSet.put( categoryProp );
            propSet.put( numberProp );
            
        }
        catch ( Exception e )
        {
            Exceptions.printStackTrace( e );
        }
        
        sheet.put( propSet );
        
        return sheet;
        
    }


    @Override
    public void propertyChange( PropertyChangeEvent evt )
    {
        firePropertyChange( evt.getPropertyName() , evt.getOldValue() , evt.getNewValue() );
    }
    
  
}
      